using System.Collections.Generic;
using UnityEngine;

public class SkinsExporterProductPanel : SkinsExporterPanel
{
	public Product selectedProduct;

	public SkinsExporterProductButton selectedProductButton;

	public SkinsExporterProductButton equippedProductButton;

	public UICenterOnChild centerOnChild;

	public UIScrollView scrollView;

	public MarketMiniProductInfo productMiniInfoPanel;

	public MarketProductInfo productInfoPanel;

	public override void Awake()
	{
		base.Awake();
	}

	public void Start()
	{
		centerOnChild.onCenter = DisableCenterOnChild;
	}

	public override void InitButtons()
	{
		base.InitButtons();
		List<Product> list = new List<Product>();
		foreach (Product value in MarketController.Instance.products["Looks"][SkinExporterCategories.instance.selected].Values)
		{
			if ((value.availableForBuy || value.Purchased) && (value.nextProduct == null || !value.nextProduct.Purchased) && (value.prevProduct == null || value.Purchased))
			{
				list.Add(value);
			}
		}
		list.Sort((Product x, Product y) => x.sortWeight.CompareTo(y.sortWeight));
		for (int i = 0; i < list.Count; i++)
		{
			string text = string.Empty;
			if (i < 10)
			{
				text = "00";
			}
			else if (i < 100)
			{
				text = "0";
			}
			text += i;
			SetProductButton(list[i], text);
		}
		if (selectedButton == null && panelButtons.Count > 0)
		{
			panelButtons[0].Select(true);
		}
		buttonsGrid.enabled = true;
		buttonsGrid.onReposition = CenterOnSelectedButton;
	}

	public void SetProductButton(Product product, string buttonName)
	{
		if ((bool)buttonExample)
		{
			SkinsExporterProductButton skinsExporterProductButton = (SkinsExporterProductButton)GetButtonFromPull();
			if (skinsExporterProductButton == null)
			{
				skinsExporterProductButton = (SkinsExporterProductButton)InstantiateButton();
			}
			skinsExporterProductButton.gameObject.SetActive(true);
			skinsExporterProductButton.InitProductButton(this, product);
			skinsExporterProductButton.name = buttonName;
			panelButtons.Add(skinsExporterProductButton);
		}
	}

	public override void ClearButtons()
	{
		for (int i = 0; i < panelButtons.Count; i++)
		{
			if (panelButtons[i] != equippedProductButton)
			{
				panelButtons[i].UnloadProductTexture();
			}
			panelButtons[i].gameObject.SetActive(false);
			buttonsPull.Add(panelButtons[i]);
		}
		panelButtons.Clear();
	}

	public override void Select(string item, bool selectDefault = true)
	{
		if (!string.IsNullOrEmpty(item) && !selected.Equals(item))
		{
			base.Select(item);
		}
	}

	public override void Unselect()
	{
		base.Unselect();
	}

	public void ResetEquippedProductButton()
	{
		if ((bool)equippedProductButton)
		{
			equippedProductButton.ResetProductButtonInfo(false);
		}
		if ((bool)selectedProductButton)
		{
			selectedProductButton.ResetProductButtonInfo(true);
		}
		productInfoPanel.UpdateInfoPanel();
	}

	private void CenterOnSelectedButton()
	{
		centerOnChild.Recenter();
		scrollView.ResetPosition();
		if (selectedProductButton != null)
		{
			int num = panelButtons.IndexOf(selectedProductButton);
			if (num > buttonsGrid.maxPerLine)
			{
				centerOnChild.CenterOn(selectedProductButton.transform);
			}
		}
	}

	private void DisableCenterOnChild(GameObject go = null)
	{
		centerOnChild.enabled = false;
	}
}
